Learning Flex Basics (Part 2): Creating a Simple Calculator with Macromedia Flex
Table of Contents
- Introduction
- Building the Calculator
- Create the Application Object
- Add a Panel for the Calculator
- Add the Calculator Display
- Add a Grid to Lay Out the Buttons
- Add the Calculator Buttons
- Create the CalculatorController Class
- Add Properties to the Controller Class
- Add Controller Methods
- Instantiate the CalculatorController Class
- Complete Code Listing for calculator.mxml
- Complete Code Listing for CalculatorController.as
- Where to Go From Here
Add a Grid to Lay Out the Buttons
To lay out the calculator buttons, you use a Grid layout
container. A Grid container is similar to an HTML table: It arranges information
in rows and columns using nested GridRow and GridItem containers. GridItem
containers have
colSpan and rowSpan properties
that work the same as the HTML <td> attributes. You are
going to lay out the buttons for the calculator in the grid. If you look
at the screen shot of the finished calculator on page
2, you will see that
you need five rows, and that the top and bottom rows will contain three
buttons, while the middle three rows contain four.
-
After the Label element, but still inside the Panel, add a Grid container block:
<mx:Grid> </mx:Grid>
-
Inside the Grid container block, add five GridRow container blocks:
<mx:GridRow></mx:GridRow> <mx:GridRow></mx:GridRow> <mx:GridRow></mx:GridRow> <mx:GridRow></mx:GridRow> <mx:GridRow></mx:GridRow>
-
Inside the first GridRow container , add three GridItem containers, and set the
colSpanof the first item to 2:<mx:GridItem colSpan="2"></mx:GridItem> <mx:GridItem></mx:GridItem> <mx:GridItem></mx:GridItem>
-
Inside each of the second, third, and fourth GridRow containers, add four GridItem containers:
<mx:GridItem></mx:GridItem> <mx:GridItem></mx:GridItem> <mx:GridItem></mx:GridItem> <mx:GridItem></mx:GridItem>
-
Inside the fifth GridRow container , add three GridItem containers, and set the
colSpanof the third item to 2:<mx:GridItem></mx:GridItem> <mx:GridItem></mx:GridItem> <mx:GridItem colSpan="2"></mx:GridItem>